<template>
  <div style="padding: 30px">
    <h4
      style="
        font-weight: 700;
        font-style: normal;
        font-size: 24px;
        color: #344563;
      "
    >
      添加用户
    </h4>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户账号">
        <el-input
          v-model="form.account"
          placeholder="请输入用户账号"
        ></el-input>
      </el-form-item>
      <el-form-item label="角色">
        <el-select v-model="form.roleName" placeholder="器材库库管">
          <el-option
            v-for="(v, i) in tableData"
            :key="i"
            :label="v"
            :value="v"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用户姓名">
        <el-input
          v-model="form.userName"
          placeholder="请输入用户姓名"
        ></el-input>
      </el-form-item>
      <el-form-item label="登录密码">
        <el-input v-model="form.pwd" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item label="手机号码">
        <el-input
          v-model="form.phoneNumber"
          placeholder="请输入手机号码"
        ></el-input>
      </el-form-item>
      <el-form-item label="备注信息">
        <el-input
          type="textarea"
          v-model="form.note"
          placeholder="请输入备注信息"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button>取消</el-button>
        <el-button type="primary" @click="postData">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        account: "",
        roleName: "",
        phoneNumber: "",
        userName: "",
        pwd: "",
        note: "",
      },
      tableData: [],
    };
  },
  methods: {
    postData: function () {
      this.$axios({
        url: "/user/add",
        method: "post",
        data: {
          account: this.form.account,
          roleName: this.form.roleName,
          phoneNumber: this.form.phoneNumber,
          userName: this.form.userName,
          pwd: this.form.pwd,
          note: this.form.note,
        },
      }).then((res) => {
        if (res.data.code == 0) {
          this.$router.push("/home/Yhgl");
        } else {
          console.log("sb");
        }
      });
    },
    postDat: function () {
      this.$axios({
        url: "/user/roleName",
        method: "post",
        data: {},
      }).then((res) => {
        /*  console.log(res.data) */
        if (res.data.code == 0) {
          this.tableData = res.data.data;
        }
      });
    },
  },
  mounted: function () {
    /* this.postData() */
    this.postDat();
  },
};
</script>